#ifndef VSMORPHBASEFUNCTION_H
#define VSMORPHBASEFUNCTION_H
#include "VSController.h"
#include "VSMorphTree.h"
#include "VSPutNode.h"
namespace VSEngine2
{
	class VSStream;
	class VSGRAPHIC_API VSMorphBaseFunction : public VSController
	{
		//RTTI
		DECLARE_RTTI;
	public:
		friend class VSMorphTree;
		virtual ~VSMorphBaseFunction() = 0;
		VSMorphBaseFunction(const VSUsedName & ShowName,VSMorphTree * pMorphTree);
		virtual bool UpdateEx(double dAppTime);
// 
// 		template<class T>
// 		T GetResult();
	protected:
		VSMorphBaseFunction();
	protected:
		VSArray<VSInputNode *> m_pInput;
		VSArray<VSOutputNode *> m_pOutput;
		VSMorphTree * m_pOwner;
		VSUsedName m_ShowName;

		bool m_bIsVisited;

		inline void SetOwner(VSMorphTree * pOwner)
		{
			VSMAC_ASSERT(pOwner);
			m_pOwner = pOwner;
		}
		void AddAllPutNodeTo(VSArray<VSPutNode *>& LinkArray);
		bool Link(const VSArray<VSPutNode *>& OldLink,const VSArray<VSPutNode *>& NewLink);
		virtual void ClearFlag();
	public:
		
		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
		virtual bool Link(VSStream & rStream);

		virtual bool Register(VSStream & rStream)const;
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);

		VSInputNode * GetInputNode(unsigned int uiNodeID)const;
		VSInputNode * GetInputNode(const VSString & NodeName)const;

		VSOutputNode * GetOutputNode(unsigned int uiNodeID)const;
		VSOutputNode * GetOutputNode(const VSString & NodeName)const;

		inline const VSUsedName & GetShowName()const
		{
			return m_ShowName;
		}

	};
	typedef VSPointer<VSMorphBaseFunction> VSMorphBaseFunctionPtr;
}
#endif